﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;

public partial class admin_user_userAdd : System.Web.UI.Page
{
    protected tb_user userbll = new tb_user();
    protected tb_log logbll = new tb_log();
    protected UserModel um = null;
    protected LogModel lm = null;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (cname.Text == string.Empty)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名不能为空！');</script>);");
            return;
        }
        if (cpwd.Text.ToLower() != twopwd.Text.ToLower())
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('密码不一致！');</script>);");
            return;
        }
        um = new UserModel();
        um.username = cname.Text.Trim();
        um.pwd = twopwd.Text.Trim();
        um.provdate = DateTime.Now;
        um.regdate = DateTime.Now;
        if (nan.Checked == true)
            um.sex = "男";
        else
            um.sex = "女";
        if (jl.Checked == true)
            um.usertype = 0;//经理
        if (ywy.Checked == true)
            um.usertype = 1;//业务员
        if (ddy.Checked == true)
            um.usertype = 2;//出纳员
      
        um.m1 = "新添加的一个员工:"+cname.Text ;        
        int uid=userbll.Add(um);
        lm = new LogModel();//日志
        lm.userid = uid;
        lm.op = "插入";
        lm.opdate = DateTime.Now;
        lm.memo = "插入一个新员工：" + um.username;
        int lid=logbll.Add(lm);
        if (uid > 0 && lid > 0)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加用户成功！');</script>);");
            this.clearData();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加乘客失败 ！');</script>");
        }
            
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.clearData();
    }
    private void clearData()
    {
        cname.Text = string.Empty;
        cpwd.Text = string.Empty;
        twopwd.Text = string.Empty;

    }
}
